import java.util.Arrays;

/**
 * @ClassName LC496
 * @Author ykx
 * @Date 2024/7/8 19:10
 * @Version 1.0
 */
public class LC496 {
    public static void main(String[] args) {
        int[] num1 = new int[]{4, 1, 2};
        int[] num2 = new int[]{1, 3, 4, 2};
        LC496 lc496 = new LC496();
        System.out.println(Arrays.toString(lc496.nextGreaterElement(num1, num2)));
    }

    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        int[] result = new int[nums1.length];
        Arrays.fill(result, -1);

        for (int i = 0; i < nums1.length; i++) {
            int from = 0;
            for (int j = 0; j < nums2.length; j++) {
                if (nums2[j] == nums1[i]) {
                    from = j;
                }
            }
            for (int j = from + 1; j < nums2.length; j++) {
                if (nums2[j] > nums1[i]) {
                    result[i] = nums2[j];
                    break;
                }
            }

        }

        return result;
    }
}
